define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'home/health/index' + location.search,
                    add_url: 'home/health/add',
                    edit_url: 'home/health/edit',
                    del_url: 'home/health/del',
                    multi_url: 'home/health/multi',
                    import_url: 'home/health/import',
                    for_url: 'home/health/index',
                    table: 'health',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: '',
                commonSearch: true,
                searchFormVisible: true,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'), formatter: function(value, row, index){
                                return ++index;
                            },operate: false},
                        {field: 'name', title: __('项目名称'), operate: 'LIKE'},
                        //{field: 'image', title: __('图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'price', title: __('价格'), operate: false},
                        // {field: 'msg', title: __('临床意义'), operate: false,
                        //     cellStyle: function () {
                        //         return{
                        //             css: {
                        //                 "max-width":"150px",
                        //                 "text-overflow": "ellipsis",
                        //                 "white-space": "initial"
                        //             }
                        //         };
                        //
                        //     }
                        // },
                        {field: 'msg', title: __('临床意义'), operate: false,
                            formatter : function(value, row, index, field){
                                return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.msg + "'>" + value + "</span>";
                            },
                            cellStyle : function(value, row, index, field){
                                return {
                                    css: {
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width":"150px"
                                    }
                                };
                            }

                        },
                        //{field: 'status', title: __("状态"), searchList: {"0":__('未发布'),"1":__('已发布')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('创建时间'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            // buttons: [{
                            //     name: 'detail',
                            //     text: __('Detail'),
                            //     icon: 'fa fa-list',
                            //     classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                            //     url: 'test/detail'
                            // }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});